package safeCommitter.test.executor.builder;

import java.io.File;
import java.util.LinkedList;
import java.util.List;

import org.testng.xml.Parser;
import org.testng.xml.XmlSuite;

/**
 * @author Luiz Henrique Rolim
 * 
 * Knows how to build TestNG's a Collection of XMLSuite from a Collection of
 * file Paths to TestNG.xml files.
 */
public class SCXmlSuiteBuilder {

	public List<XmlSuite> getXmlSuitesFromFiles(final String filePaths) {
		String[] splitFilePath = filePaths.split(",");
		List<XmlSuite> builtSuite = new LinkedList<XmlSuite>();
		for (String s : splitFilePath) {
			File file = new File(s);
			if (!file.exists()) {
				continue;
			}
			try {
				Parser parser = new Parser(s);
				builtSuite.addAll(parser.parse());
			} catch (Exception e) {
				e.printStackTrace();
				continue;
			}
		}
		return builtSuite;

	}

}
